/**
 * Copyright (C) 2015-2016 Guangzhou Xunhong Network Technology Co., Ltd. All rights reserved.
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * http://www.apache.org/licenses/LICENSE-2.0
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.jxccp.ui.view.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.jxccp.im.util.log.JXLog;
import com.jxccp.ui.R;
import com.jxccp.ui.entities.ZhuiyiLoanOrderEntity;
import com.jxccp.ui.entities.ZhuiyiProductOrderEntity;

import java.util.List;

public class ZhuiyiLoanOrderListAdapter extends JXBasicAdapter<ZhuiyiLoanOrderEntity, ListView> {

    private LayoutInflater mInflater;

    String[] loanOrderStatusArr;

    String[] loanOrderTypesArr;

    public ZhuiyiLoanOrderListAdapter(Context context, List<ZhuiyiLoanOrderEntity> list) {
        super(context, list);
        mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        loanOrderStatusArr = context.getResources().getStringArray(R.array
                .jx_zhuiyi_loan_order_status);
        loanOrderTypesArr = context.getResources().getStringArray(R.array
                .jx_zhuiyi_loan_order_type);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.jx_zhuiyi_loan_order_item, null);
        }
        ZhuiyiLoanOrderEntity entity = list.get(position);
        TextView loanOrderStatus = (TextView) convertView.findViewById(R.id.tv_loan_order_status);
        TextView orderId = (TextView) convertView.findViewById(R.id.tv_loan_order_id);
        TextView loanReason = (TextView) convertView.findViewById(R.id.tv_loan_reason);
        TextView loanTimeAndType = (TextView) convertView.findViewById(R.id.tv_load_time_and_type);
        TextView loanAmt = (TextView) convertView.findViewById(R.id.tv_loan_amt);
        ImageView loanImg = (ImageView) convertView.findViewById(R.id.iv_loan_img);

        int statusNum = 0;
        if (entity.getOrderStatus() >= 1 && entity.getOrderStatus() <= 12){
            statusNum = entity.getOrderStatus() -1;
        }
        loanOrderStatus.setText(loanOrderStatusArr[statusNum]);
        orderId.setText(context.getString(R.string.jx_order_num) + entity.getOrderId());
        loanReason.setText(entity.getLoanReason());
        String loanType = loanOrderTypesArr[0];
        switch (entity.getLoanType()) {
            case ZhuiyiLoanOrderEntity.ORDER_LOAN_TYPE_BAOMIHUA:
                loanType = loanOrderTypesArr[0];
                break;
            case ZhuiyiLoanOrderEntity.ORDER_LOAN_TYPE_HAIHUA:
                loanType = loanOrderTypesArr[1];
                break;
            case ZhuiyiLoanOrderEntity.ORDER_LOAN_TYPE_QUDIANHUA:
                loanType = loanOrderTypesArr[2];
                break;
            default:
                break;
        }
        loanTimeAndType.setText(entity.getOrderTime() + " " + loanType);
        loanAmt.setText("￥"+entity.getLoanAmt());


        return convertView;
    }

    public void refresh(List<ZhuiyiLoanOrderEntity> orderList) {
        this.list.clear();
        this.list.addAll(orderList);
        notifyDataSetChanged();
    }

}
